import unittest
import requests


class TestEmp(unittest.TestCase):
    def test01_add_emp(self):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        header = {"Authorization": "Bearer 5314d1f9-f0ba-4c9f-9ad7-97be26313c79"}
        json_data = {"username": "tom01",
                     "mobile": "13758488180",
                     "workNumber": "9527"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("添加员工：", resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test02_query_emp(self):
        url_query = "http://ihrm-test.itheima.net/api/sys/user/1451813140852375552"
        header = {"Authorization": "Bearer 5314d1f9-f0ba-4c9f-9ad7-97be26313c79"}
        resp = requests.get(url_query, headers=header)
        print("查询员工：", resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test03_modify_emp(self):
        url_query = "http://ihrm-test.itheima.net/api/sys/user/1451813140852375552"
        header = {"Authorization": "Bearer 5314d1f9-f0ba-4c9f-9ad7-97be26313c79"}
        json_data = {"username": "小小"}
        resp = requests.put(url_query, headers=header, json=json_data)
        print("修改员工：", resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test04_delete_emp(self):
        url_query = "http://ihrm-test.itheima.net/api/sys/user/1451813140852375552"
        header = {"Authorization": "Bearer 5314d1f9-f0ba-4c9f-9ad7-97be26313c79"}
        resp = requests.delete(url_query, headers=header, )
        print("删除员工：", resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    
